/*     */ package cc.s2m.web.s2mBlog.controller.admin;
/*     */ 
/*     */ import cc.s2m.util.BeanConverter;
/*     */ import cc.s2m.util.Page;
/*     */ import cc.s2m.web.s2mBlog.controller.base.BaseController;
/*     */ import cc.s2m.web.s2mBlog.pojo.Articles;
/*     */ import cc.s2m.web.s2mBlog.pojo.ArticlesContent;
/*     */ import cc.s2m.web.s2mBlog.pojo.ArticlesTags;
/*     */ import cc.s2m.web.s2mBlog.pojo.Tags;
/*     */ import cc.s2m.web.s2mBlog.service.IArticles;
/*     */ import cc.s2m.web.s2mBlog.service.IArticlesContent;
/*     */ import cc.s2m.web.s2mBlog.service.IArticlesTags;
/*     */ import cc.s2m.web.s2mBlog.service.ITags;
/*     */ import cc.s2m.web.s2mBlog.vo.Expressions;
/*     */ import cc.s2m.web.s2mBlog.vo.VO;
/*     */ import com.google.common.base.Strings;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ 
/*     */ @Controller("admin_ArticlesController")
/*     */ @RequestMapping({"/admin/articles"})
/*     */ public class ArticlesController extends BaseController
/*     */ {
/*     */ 
/*     */   @Autowired
/*     */   private IArticles articlesService;
/*     */ 
/*     */   @Autowired
/*     */   private ITags tagsService;
/*     */ 
/*     */   @Autowired
/*     */   private IArticlesTags articlesTagsService;
/*     */ 
/*     */   @Autowired
/*     */   private IArticlesContent articlesContentService;
/*     */ 
/*     */   @RequestMapping({"/list"})
/*     */   public String list(Model model, Articles bean, Integer page)
/*     */   {
/*  44 */     if (page == null) page = Integer.valueOf(1);
/*  45 */     Map map = new HashMap();
/*  46 */     if (bean != null) {
/*  47 */       map.putAll(BeanConverter.toMap(bean, false));
/*  48 */       model.addAttribute("bean", bean);
/*     */     }
/*  50 */     Page pageBean = this.articlesService.getPage(page.intValue(), 50, null, map);
/*  51 */     model.addAttribute("pageBean", pageBean);
/*  52 */     return "admin/articles";
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"/add"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public String add(Model model, Integer id) {
/*  57 */     Tags vo = new Tags();
/*  58 */     List tags = this.tagsService.getList(vo, null);
/*  59 */     model.addAttribute("tags", tags);
/*  60 */     if (id != null) {
/*  61 */       Articles bean = (Articles)this.articlesService.selectByPrimaryKey(id);
/*  62 */       model.addAttribute("bean", bean);
/*  63 */       ArticlesTags condition = new ArticlesTags();
/*  64 */       condition.setAid(id);
/*  65 */       List tagsSel = this.articlesTagsService.getList(condition, null);
/*  66 */       model.addAttribute("tagsSel", tagsSel);
/*  67 */       ArticlesContent content = (ArticlesContent)this.articlesContentService.selectByPrimaryKey(id);
/*  68 */       model.addAttribute("content", content);
/*     */     }
/*  70 */     return "admin/articles_add";
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"/view"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public String view(Model model, Integer id) {
/*  75 */     if (id != null) {
/*  76 */       Articles bean = (Articles)this.articlesService.selectByPrimaryKey(id);
/*  77 */       model.addAttribute("bean", bean);
/*     */     }
/*  79 */     return "admin/articles_view";
/*     */   }
/*     */   @RequestMapping(value={"/save"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   @ResponseBody
/*     */   public String save(Model model, Articles bean, Integer[] tags, String content) {
/*  85 */     if (bean == null) {
/*  86 */       return "empty";
/*     */     }
/*  88 */     if ((tags == null) || (tags.length == 0)) {
/*  89 */       return "noTags";
/*     */     }
/*  91 */     if (Strings.isNullOrEmpty(content)) {
/*  92 */       return "noContent";
/*     */     }
/*  94 */     if (Strings.isNullOrEmpty(bean.getUrl())) {
/*  95 */       return "noUrl";
/*     */     }
/*  97 */     if (bean.getId() == null)
/*     */     {
/*  99 */       Articles condition = new Articles();
/* 100 */       condition.setUrl(bean.getUrl());
/* 101 */       condition = (Articles)this.articlesService.getByCondition(condition);
/* 102 */       if (condition != null) {
/* 103 */         return "exists";
/*     */       }
/* 105 */       this.articlesService.insertSelective(bean);
/*     */     }
/*     */     else {
/* 108 */       Articles avo = new Articles();
/* 109 */       avo.setUrl(bean.getUrl());
/* 110 */       VO vo = new VO();
/* 111 */       vo.and(Expressions.ne("id", bean.getId()));
/* 112 */       avo = (Articles)this.articlesService.getByCondition(avo, vo);
/* 113 */       if (avo != null) {
/* 114 */         return "exists";
/*     */       }
/* 116 */       this.articlesService.updateByPrimaryKeySelective(bean);
/*     */ 
/* 118 */       ArticlesTags condition = new ArticlesTags();
/* 119 */       condition.setAid(bean.getId());
/* 120 */       List<ArticlesTags> list = this.articlesTagsService.getList(condition, null);
/* 121 */       for (ArticlesTags atag : list)
/*     */       {
/* 123 */         this.articlesTagsService.deleteByPrimaryKey(atag.getId());
/* 124 */         Tags tag = (Tags)this.tagsService.selectByPrimaryKey(atag.getTid());
/* 125 */         tag.setNumber(Integer.valueOf(this.tagsService.getTagArticleNumber(atag.getTid().intValue())));
/* 126 */         this.tagsService.updateByPrimaryKeySelective(tag);
/*     */       }
/*     */     }
/* 129 */     Integer[] arr$ = tags; int len$ = arr$.length; for (int i$ = 0; i$ < len$; i$++) { int tagId = arr$[i$].intValue();
/* 130 */       ArticlesTags atag = new ArticlesTags();
/* 131 */       atag.setAid(bean.getId());
/* 132 */       atag.setTid(Integer.valueOf(tagId));
/* 133 */       this.articlesTagsService.insertSelective(atag);
/* 134 */       Tags tag = (Tags)this.tagsService.selectByPrimaryKey(atag.getTid());
/* 135 */       tag.setNumber(Integer.valueOf(this.tagsService.getTagArticleNumber(atag.getTid().intValue())));
/* 136 */       this.tagsService.updateByPrimaryKeySelective(tag);
/*     */     }
/*     */ 
/* 139 */     ArticlesContent articlesContent = (ArticlesContent)this.articlesContentService.selectByPrimaryKey(bean.getId());
/* 140 */     if (articlesContent == null) {
/* 141 */       articlesContent = new ArticlesContent();
/* 142 */       articlesContent.setId(bean.getId());
/* 143 */       articlesContent.setContent(content);
/* 144 */       this.articlesContentService.insert(articlesContent);
/*     */     } else {
/* 146 */       articlesContent.setContent(content);
/* 147 */       this.articlesContentService.updateByPrimaryKey(articlesContent);
/*     */     }
/* 149 */     return "success";
/*     */   }
/*     */   @RequestMapping(value={"/del"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   @ResponseBody
/*     */   public String del(Integer id) {
/* 155 */     Articles bean = (Articles)this.articlesService.selectByPrimaryKey(id);
/* 156 */     if (bean != null) {
/* 157 */       this.articlesService.deleteByPrimaryKey(id);
/*     */     }
/* 159 */     ArticlesTags condition = new ArticlesTags();
/* 160 */     condition.setAid(id);
/* 161 */     List<ArticlesTags> list = this.articlesTagsService.getList(condition, null);
/* 162 */     for (ArticlesTags atag : list) {
/* 163 */       this.articlesTagsService.deleteByPrimaryKey(atag.getId());
/* 164 */       Tags tag = (Tags)this.tagsService.selectByPrimaryKey(atag.getTid());
/* 165 */       tag.setNumber(Integer.valueOf(this.tagsService.getTagArticleNumber(atag.getTid().intValue())));
/* 166 */       this.tagsService.updateByPrimaryKeySelective(tag);
/*     */     }
/* 168 */     this.articlesContentService.deleteByPrimaryKey(id);
/* 169 */     return "success";
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\s2mBlog.zip
 * Qualified Name:     s2mBlog-3.0.0.WEB-INF.classes.cc.s2m.web.s2mBlog.controller.admin.ArticlesController
 * JD-Core Version:    0.6.1
 */